package com.wego.converter.trans;

import com.wego.common.utils.TransUtil;
import com.wego.converter.CartItemConverter;
import com.wego.entity.domain.CartItem;
import com.wego.entity.domain.Goods;
import com.wego.entity.vo.manager.CartItemVO;
import com.wego.service.GoodsService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CartItemTrans {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private CartItemConverter cartItemConverter;

    @Getter
    private TransUtil<CartItem, CartItemVO> instance = new TransUtil<>() {
        @Override
        public CartItemVO tObj2VObj(CartItem cartItem) {
            CartItemVO cartItemVO = cartItemConverter.cart2CartVO(cartItem);

            final Goods goods = goodsService.selectByPrimaryKey(cartItem.getGoodsId());
            cartItemVO.setGoodsPic(goods.getPic());
            cartItemVO.setGoodsSellingPoint(goods.getSellingPoint());
            cartItemVO.setGoodsPrice(goods.getPrice2());
            cartItemVO.setGoodsUnit(goods.getUnit());
            cartItemVO.setGoodsName(goods.getName());

            return cartItemVO;
        }
    };

}
